package com.promise.jokerdream.ui.components

import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.promise.jokerdream.model.log.ExecutionLog
import com.promise.jokerdream.ui.theme.AppColors

/**
 * 可复用的日志项组件
 */
@Composable
fun LogItem(
    log: ExecutionLog,
    modifier: Modifier = Modifier
) {
    val isError = log.result < 0
    
    Card(
        modifier = modifier
            .fillMaxWidth()
            .then(
                if (isError) {
                    Modifier.border(
                        width = 0.4.dp,
                        color = AppColors.ErrorText,
                        shape = RoundedCornerShape(8.dp)
                    )
                } else {
                    Modifier
                }
            ),
        colors = CardDefaults.cardColors(
            containerColor = AppColors.SuccessBackground // 统一白色背景
        ),
        shape = RoundedCornerShape(8.dp)
    ) {
        Column(
            modifier = Modifier.padding(12.dp)
        ) {
            // 第一行：时间
            Text(
                text = log.getFormattedTime(),
                style = MaterialTheme.typography.bodyMedium,
                color = if (isError) AppColors.ErrorText else AppColors.TextSecondary,
                fontWeight = FontWeight.Normal
            )
            
            // 第二行：[动作]信息
            Text(
                text = "[${log.operation}] ${log.message}",
                style = MaterialTheme.typography.bodyMedium,
                color = if (isError) AppColors.ErrorText else AppColors.TextPrimary,
                fontWeight = if (isError) FontWeight.Medium else FontWeight.Normal,
                modifier = Modifier.padding(top = 4.dp)
            )
        }
    }
}
